﻿using DocumentFormat.OpenXml.Wordprocessing;
using FileManager.Model;
using FileManager.Util;
using FileManager.ViewModel;
using Stateless;
using Stateless.Graph;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Imaging;
using Windows.ApplicationModel.Calls;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock;

namespace FileManager.MyProcess
{
    /// <summary>
    /// 
    /// </summary>
    internal class Demo
    {
       
        private StateMachine<State, Trigger> SM;
        private StateMachine<State, Trigger>.TriggerWithParameters<FileInfo> updatAddressTrigger;


        public enum State
        {
            开始,//开始
            电话连接,//检查文件名称
            电话等待,//确定文件是否相同
            等待结束,//覆盖文件
            结束//结束
        }

        // 定义触发器
        public enum Trigger
        {
            拨打电话,
            我有事,
            我没事,
            知道了
        }




        public void Fire(Trigger trigger)
        {
            SM.Fire(trigger);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="viewModel">当前view页面</param>
        /// <param name="disPlayPic">需要保存的图片（可能是修改后）</param>
        /// <param name="savePath">保存地址</param>
        /// <param name="letterPath">当前委托书地址</param>
        internal Demo()
        {

            SM = new StateMachine<State, Trigger>(State.开始);
            // 定义状态转换和动作
            SM.Configure(State.开始)
                .Permit(Trigger.拨打电话, State.电话连接);


            //检测是否有同名文件
            SM.Configure(State.电话连接)
                .OnEntry(() => Debug.WriteLine("电话已连接"))
                .OnExit(() => {
                    Debug.WriteLine("电话已挂断");
                    Debug.WriteLine($"电话已挂断,在连接状态{SM.IsInState(State.电话连接)}");
                    Debug.WriteLine($"电话已挂断,在等待状态{SM.IsInState(State.电话等待)}");



                     })
                .PermitIf(Trigger.我有事, State.电话等待,()=>true)
                .PermitIf(Trigger.我没事, State.等待结束,()=>false)
                .Permit(Trigger.知道了, State.结束);


            //覆盖文件
            SM.Configure(State.电话等待)
                .SubstateOf(State.电话连接)
                .OnEntry(() => Debug.WriteLine("等待开始"))
                .OnExit(() => Debug.WriteLine("等待结束"));

            //移动文件
            SM.Configure(State.等待结束)
                .SubstateOf(State.电话连接)
                .OnEntry(() => Debug.WriteLine("等待结束"))
                .OnExit(() => Debug.WriteLine("准备答复"));

         

            string graph = MermaidGraph.Format(SM.GetInfo());
            string gr = UmlDotGraph.Format(SM.GetInfo());
            Debug.WriteLine(graph);
        }
    } 
}







